package client.ui;

import client.network.BanchoClient;
import common.enums.RequestType;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static javafx.stage.StageStyle.DECORATED;

public class Main extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception{
        //设置一个控制所有界面的控制器
        stageController controlAllStage = new stageController();

        //加载主界面
        controlAllStage.loadStage("primaryWindows", "/ui/primaryUI.fxml");
        controlAllStage.getStage("primaryWindows").setOnShown(event -> {
            BanchoClient.SendRequest(RequestType.Friend_GetList, null);
            BanchoClient.SendRequest(RequestType.Group_List, null);
        });
        controlAllStage.getStage("primaryWindows").setResizable(false);

        //加载登录界面到控制器
        controlAllStage.loadStage("loginWindows","/ui/loginUI.fxml",DECORATED);  //会返回一个root，用来操作其他事情
        Stage loginStage = controlAllStage.getStage("loginWindows");
        loginStage.setTitle("TT");
        loginStage.setResizable(false);
        loginStage.setMaxHeight(450);
        loginStage.setMaxWidth(576);

        //加载注册界面到控制器
        controlAllStage.loadStage("registerWindows","/ui/registerUI.fxml",DECORATED);

        //加载聊天界面到控制器
        controlAllStage.loadStage("textWindows","/ui/textUI.fxml",DECORATED);


        //管理多个舞台的状态
        controlAllStage.setStage("loginWindows");
    }

    public static Runnable client;
    public static ExecutorService executorService;
    public static void main(String[] args) throws IOException {
        client = BanchoClient.Create();
        executorService = Executors.newSingleThreadExecutor();
        executorService.execute(client);
        launch(args);
    }
}
